import CryptoJS from 'crypto-js/crypto-js'
const key = CryptoJS.enc.Utf8.parse('!QAZ2wsx')
const iv = CryptoJS.enc.Utf8.parse() // 偏移量

const paramsCrypto = {
  /**
 * AES加密 ：字符串 key iv  返回base64
 */
  encrypt: function (word) {
    const srcs = CryptoJS.enc.Utf8.parse(word)
    const encrypted = CryptoJS.AES.encrypt(srcs, key, {
      // iv: iv,
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
    })
    return CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
  },

  /**
   * AES 解密 ：字符串 key iv  返回base64
   *  */
  decrypt: function (word) {
    const base64 = CryptoJS.enc.Base64.parse(word)
    const src = CryptoJS.enc.Base64.stringify(base64)

    const decrypt = CryptoJS.AES.decrypt(src, key, {
      // iv: iv,
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7,
    })
    return CryptoJS.enc.Utf8.stringify(decrypt)
  }

}


export default {
  install: function (Vue) {
    Object.defineProperty(Vue.prototype, '$paramsCrypto', { value: paramsCrypto })
  },
}